package com.zhiyou100.service;

import com.zhiyou100.dao.ExamDao;
import com.zhiyou100.entity.Exam;
import com.zhiyou100.exception.ExamException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutionException;

@Service
public class ExamServiceImp   implements  ExamService{
    public List<Exam> getAllByEnameOrEtime(String ename, Date etime){
          return examDao.getAllByEnameOrEtime(ename,etime);
    }
    @Autowired
    private ExamDao  examDao;
    public void addOne(Exam e) throws ExamException{
         //判断名字是否存在
         Exam dbExam1=examDao.getOneByEname(e.getEname());
         if(dbExam1!=null){
             throw new ExamException("考试名字已经存在！");
         }
         //判断时间是否存在
        Exam dbExam2=examDao.getOneByEtime(e.getEtime());
        if(dbExam2!=null){
            throw new ExamException("考试时间已经存在！");
        }
         examDao.addOne(e);
    }
    public List<Exam>  getAllFenYe(int startIndex,int pageSize){
        return examDao.getAllFenYe(startIndex,pageSize);
    }

    @Override
    public void deleteOne(Integer id) {
          examDao.deleteOne(id);
    }

    @Override
    public void updateOne(Exam o) {
        examDao.updateOne(o);
    }

    @Override
    public List<Exam> getAll() {
        return examDao.getAll();
    }

    @Override
    public Exam getOne(Integer id) {
        return examDao.getOne(id);
    }
}
